<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>法人关联企业信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body>
        <form id="cust_cst_corp_rl_comp_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
                <div class="fieldBox col_50">
                    <div class="label">关系</div>
                    <div class="field">
                        <select name="rlTypCd" id="rlTypCd" data-value="" validate="{required:true, select: true}">
                             <c:forEach items="${searchSelectRlTypCdList }" var="kv" begin="0" step="1" varStatus="status">
								<c:if test="${status.index == 0}">
									<option value="${kv.key }" checked >${kv.value }</option>
								</c:if>
								<c:if test="${status.index != 0}">
									<option value="${kv.key }">${kv.value }</option>
								</c:if>
							 </c:forEach>
                        </select>
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">企业名称</div>
                    <div class="field">
                        <input name="compNm" id="compNm" type="text" class="ui-textbox" value="" validate="{required:true,nmcharacter:true,maxlength:25}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">法人代表</div>
                    <div class="field">
                        <input name="corpRep" id="corpRep" type="text" class="ui-textbox" value="" validate="{required:true,nmcharacter:true,maxlength:15}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">联系方式</div>
                    <div class="field">
                        <input name="tel" id="tel" type="text" class="ui-textbox" value="" validate="{mobileAndFixedPhone:true}">
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">单位地址</div>
                    <div class="field">
                        <input name="addr" id="addr" type="text" class="ui-textbox" value="" validate="{maxlength:70}">
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">备注</div>
                    <div class="field" style="width: 100%;">
                        <textarea name="rlRem" id="rlRem" rows="4" class="l-textarea" style="width:90%" validate="{maxlength:100}"></textarea>
                    </div>
                </div>
                <!-- hide data -->
		        <div class="fieldBox col_100" style="display:none;">
		          <div class="field">
		              <input name=cstId id="cstId" type="text" class="ui-textbox" value="${cstId}">
		              <input name="crcId" id="crcId" type="text" class="ui-textbox" value="${crcId}">
		          </div>
		        </div>
            </div>
        </form>
	<script>
		$(function() {
		   $("#cust_cst_corp_rl_comp_form").ligerForm({
                validate: true
           });
	       initData();
		});
		
		frameElement.dialog.onOk = function () {
			save();
		}
		
		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}
		
		//保存
		function save(){
			var ligerForm = liger.get("cust_cst_corp_rl_comp_form");
            if (!ligerForm.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            
            var crcId = $("#crcId").val();
            var url = '<%=path%>/customer/cstcorprlcomp/add.do';
            if(crcId != ""){
            	url = '<%=path%>/customer/cstcorprlcomp/modify.do';
            	data["id"]= crcId;
            }
            var wait_dialog= $.ligerDialog.SQalert({
	            content: LogUtils.LOG_CMM_LOADING,
	            SQ_type: "waitting",
	            onClose: function () {
	            }
	        });
            
            //设置客户ID
            var cstId = $("#cstId").val();
            data["cstId"]= cstId;
            $.ajax({
        		type: 'post',
        		dataType:'json',
        		data:data,
        		url: url,
        		success:function(msg){
        			wait_dialog.close();
        			 if(msg.success == 1){
        				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
        				 parent.cstCorpRlCompGrid.setParm("cstId",cstId);
        				 parent.cstCorpRlCompGrid.reload();
        				 frameElement.dialog.close();
        			 }else{
        				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
        			 }
        		}
        	});
		}

		
		function initData(){
			var crcId = $("#crcId").val();
	    	if(!crcId)return;
	    	var wait_dialog= $.ligerDialog.SQalert({
	            content: LogUtils.LOG_CMM_LOADING,
	            SQ_type: "waitting",
	            onClose: function () {
	            }
	        });

	    	var _url = '<%=path%>/customer/cstcorprlcomp/getById.do';
	    	$.ajax({
	    		type: 'get',
	    		dataType:'json',
	    		data:{id:crcId},
	    		url: _url,
	    		success:function(msg){
	    			wait_dialog.close();
	    			 if(msg.success == 1){
	    				 setData(msg.data);//设置数据
	    			 }else{
	    				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			 }
	    		}
	    	});
    	}
		
		//设置页面数据
	    function setData(data){
	    	var form = new liger.get("cust_cst_corp_rl_comp_form");
	    	form.setData({
	    		rlTypCd:data.rlTypCd,
	    		compNm:data.compNm,
	    		corpRep:data.corpRep,
	    		tel:data.tel,
	    		rlRem:data.rlRem,
	    		addr:data.addr
	    	});
		};
	</script>
</body>
</html>